Skip to content

feat: Improve OAuth account creation flows#306

Closed
hhvrc wants to merge 2 commits into
developfrom
feature/oauth-flow-improvements
Closed

feat: Improve OAuth account creation flows#306
hhvrc wants to merge 2 commits into
developfrom
feature/oauth-flow-improvements

Conversation

@hhvrc
Copy link
Copy Markdown
Contributor

@hhvrc hhvrc commented May 24, 2026

No description provided.

@hhvrc hhvrc self-assigned this May 24, 2026
Copilot AI review requested due to automatic review settings May 24, 2026 17:36
@hhvrc hhvrc added the feature New feature or request label May 24, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves the OAuth signup/account-creation UX by distinguishing username vs email conflicts and adding a password-based linking endpoint for “email already exists” OAuth signups.

Changes:

  • Split OAuth-only account creation conflicts into UsernameAlreadyTaken vs EmailAlreadyTaken { HasPassword } and surface more specific problems from signup-finalize.
  • Add POST /{provider}/signup-link-password to link an in-flight OAuth signup to an existing password account.
  • Introduce additional OAuth/account problem codes to support the new flow and error routing.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Common/Errors/AccountError.cs Adds new account conflict problems for email-taken cases that do/don’t allow password linking.
API/Services/Account/IAccountService.cs Updates the OAuth-only account creation contract to return distinct conflict markers.
API/Services/Account/AccountService.cs Implements conflict differentiation (username vs email, plus password-present hint).
API/OAuth/OAuthError.cs Adds new OAuth problems for provider-already-linked and link failure.
API/Models/Requests/OAuthLinkPasswordRequest.cs Adds request model for password-based linking endpoint.
API/Controller/OAuth/SignupLinkWithPassword.cs New endpoint to authenticate by password and link OAuth identity to an existing account.
API/Controller/OAuth/SignupFinalize.cs Updates finalize endpoint to return more specific conflict problems and preserve the flow cookie on conflict.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +136 to +140
// Reuse existing guards. Blacklist hits are reported as username-taken so we don't leak
// the existence of the blacklist or the validity of the email domain to anonymous callers.
if (await IsUserNameBlacklisted(username) || await IsEmailProviderBlacklisted(email))
return new AccountWithEmailOrUsernameExists();
return new UsernameAlreadyTaken();

Comment on lines 216 to +220
{
await tx.RollbackAsync();
return new AccountWithEmailOrUsernameExists();

// Map known unique indexes to specific outcomes.
switch (pgEx.ConstraintName)
Comment on lines +234 to +238
// Ambiguous constraint — re-query both. Prefer the email outcome.
var emailRow = await _db.Users
.Where(u => u.Email == email)
.Select(u => new { HasPassword = u.PasswordHash != null })
.FirstOrDefaultAsync();
Comment on lines +42 to +47
/// <returns>
/// Success with the created user, or a conflict marker distinguishing username vs. email collision.
/// When both collide, prefer <see cref="EmailAlreadyTaken"/> (the email path enables linking via
/// password login; username conflict can only be retried).
/// </returns>
Task<OneOf<Success<User>, UsernameAlreadyTaken, EmailAlreadyTaken>> CreateOAuthOnlyAccountAsync(string email, string username, string provider, string providerAccountId, string? providerAccountName, bool isEmailTrusted);

_logger.LogInformation(
"Linked OAuth provider {Provider} (external id {ExternalId}) to existing user {UserId} via password",
provider, auth.ExternalAccountId, account.Id);
@hhvrc hhvrc closed this May 24, 2026
@hhvrc hhvrc deleted the feature/oauth-flow-improvements branch May 24, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants